package com.cius.ssm.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ciuscheung on 17/4/13.
 */
public class HandlerInterceptor1 implements HandlerInterceptor {

    //进人Handler之前执行
    //用于身份认证,身份授权
    //如果身份认证不通过,表示当前用户没有登录,需要此方法拦截不再向下执行
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        //return true表示放行
        //return false 表示拦截,不向下执行
        System.out.println("HandlerInterceptor1.preHandle");
        return true;
    }

    //进入handler之后,返回modelAndView之前执行
    //应用场景:从modelAndView出发,将公用模型数据(比如菜单导航)在这里传到视图,也可以在这指定同意视图
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("HandlerInterceptor1.postHandle");
    }

    //执行handler完成执行此方法
    //应用场景:同意日志管理,同意日志处理
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("HandlerInterceptor1.afterCompletion");
    }
}
